package tech.dx.springdb.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.dx.springdb.entity.CourseCategories;
import tech.dx.springdb.respository.CourseCategoriesRepository;
import tech.dx.springdb.service.CourseCategoriesService;

import java.util.Optional;

/**
 * @ClassName CourseCategoriesServiceImpl
 * @Description TODO
 * @Author daoxuan
 * @Date 2019/4/1 12:20
 * @Version 1.0
 */
@Service
public class CourseCategoriesServiceImpl implements CourseCategoriesService {
    @Autowired
    private CourseCategoriesRepository categoriesRepository;

    @Override
    public Optional<CourseCategories> getById(long id) {
        return categoriesRepository.findById(id);
    }

    @Override
    public CourseCategories add(CourseCategories classtype) {
        return categoriesRepository.save(classtype);
    }

    @Override
    public CourseCategories update(CourseCategories classtype) {
        return  add(classtype);
    }

    @Override
    public void del(long id) {
        if (isExitById(id))
        categoriesRepository.deleteById(id);
    }

    @Override
    public boolean isExitById(long id) {
        return getById(id).isPresent() ? true : false;
    }
}
